<template>
  <div class="info_content">
    <div v-if="show[0]">
      <el-card class="box-card max">
        <div slot="header" class="clearfix">
          <span>设备概览 <span class="iconfont">&#xe605;</span></span>
          <el-button style="float: right; padding: 3px 0" type="text"
            >绑定设备</el-button
          >
        </div>
        <div class="text item">
          <ul class="shebei_con">
            <li>
              <img src="../../assets/gateway.png" />
              <div class="middle_line" />
            </li>
            <li>
              <div class="info_c">
                <h1>{{ deviceObj.LoRaWAN.total }}</h1>
                <h4>LoRaWAN</h4>
                <h4>网关</h4>
              </div>
              <div class="middle_line" />
            </li>
            <li>
              <div class="info_c">
                <h1>{{ deviceObj.LoRaPP.total }}</h1>
                <h4>LoRaPP</h4>
                <h4>网关</h4>
              </div>
              <div class="middle_line" />
            </li>
            <li>
              <div class="info_c">
                <h1>{{ deviceObj.group }}</h1>
                <h4>&nbsp;</h4>
                <h4>群组</h4>
              </div>
              <div class="long_line" />
            </li>
            <li>
              <span class="iconfont">&#xe60c;</span>
            </li>
            <li>
              <div class="info_c">
                <h1>{{ deviceObj.sensor.total }}</h1>
                <h4>传感器节点</h4>
              </div>
            </li>
          </ul>
        </div>
      </el-card>
    </div>

    <div v-if="show[1]">
      <el-card class="box-card max">
        <div slot="header" class="clearfix">
          <span>监控 <span class="iconfont">&#xe605;</span></span>
        </div>
        <div class="text item">
          <ul class="jiankong">
            <li>
              网关离线
              <span class="green">{{
                deviceObj.LoRaPP.offline + deviceObj.LoRaWAN.offline
              }}</span>
            </li>
            <li>
              节点离线
              <span class="green">{{ deviceObj.sensor.offline }}</span>
            </li>
            <li>
              传感器低电量
              <span class="red">{{ deviceObj.sensor.lowBattery }}</span>
            </li>
          </ul>
        </div>
      </el-card>
    </div>

    <div v-if="show[2]">
      <el-card class="box-card max">
        <div slot="header" class="clearfix">
          <span>公告 <span class="iconfont">&#xe605;</span></span>
        </div>
        <div class="text item">
          <ul class="ggao">
            <li>
              <span class="iconfont">&#xe8c9;</span>senseCAP V3.02021-12-15
              14:28:08
            </li>
            <li>
              <span class="iconfont">&#xe8c9;</span>senseCAP V3.02021-12-15
              14:28:08
            </li>
          </ul>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { $deviceCount } from "@/api/api.js";

export default {
  name:"OverView",
  props:{
    'show':{
      type:Array,
      default:()=>[true,true,true]
    }
  },
  data(){
    return {
      deviceObj: {
        sensor: "",
        LoRaPP: "",
        LoRaWAN: "",
        group: "",
      }
    }
  },
  created() {
    this.getDevice();
  },
  methods: {
    //获取设备概览数据
    getDevice() {
      $deviceCount().then((res) => {
        console.log(res);
        this.deviceObj = res.data.data;
      });
    },
  },
};
</script>

<style scoped lang="scss">
.info_content {
  width: 100%;
  min-width: 1200px;
  height: 220px;
  display: flex;
  padding: 10px 0;
  .max {
    width: 100%;
    height: 100%;
  }

  > div:nth-of-type(1) {
    flex: 1 1 auto;
    box-sizing: border-box;
    padding-right: 10px;

    .shebei_con {
      display: flex;
      li {
        flex: 1 1 auto;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .info_c {
          padding-left: 30px;
          text-align: left;
        }
      }

      li:first-child {
        justify-content: space-between;
        > img {
          width: 50px;
        }
      }

      li:nth-last-of-type(2) {
        justify-content: center;
        padding-left: 30px;

        .iconfont {
          font-size: 50px;
          color: rgb(153, 153, 153);
          transform: rotate(180deg);
        }
      }

      li:last-child {
        justify-content: flex-end;
      }

      .middle_line {
        width: 2px;
        height: 50px;
        box-sizing: border-box;
        border-right: 1px solid rgb(226, 226, 226);
      }

      .long_line {
        width: 2px;
        height: 100px;
        box-sizing: border-box;
        border-right: 1px solid rgb(226, 226, 226);
      }
    }
  }

  > div:nth-of-type(2) {
    width: 400px;
    padding-right: 5px;
    box-sizing: border-box;

    .jiankong {
      li {
        display: flex;
        padding: 5px;
        font-weight: bold;
        font-size: 15px;
        justify-content: space-between;

        > span {
          border-radius: 10px;
          display: inline-block;
          width: 30px;
        }
        .red {
          background-color: rgb(255, 166, 166);
          color: rgb(180, 0, 0);
          padding: 1px 5px;
        }
        .green {
          background-color: rgb(225, 255, 166);
          color: rgb(112, 168, 0);
          padding: 1px 5px;
        }
      }
    }
  }

  > div:nth-of-type(3) {
    padding-left: 5px;
    box-sizing: border-box;
    width: 400px;

    .ggao {
      li {
        width: 100%;
        padding: 5px 0px;

        > span {
          color: rgb(20, 173, 0);
          font-weight: bold;
        }
      }
    }
  }
}
</style>